import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int f1=0;
        int f2=1;
        while(f2<n){
            int f3=f1+f2;
            f1=f2;
            f2=f3;
        }
        int min=Math.min(n-f1,f2-n);
        System.out.println(min);
    }
}
